<!-- 2025-2-12 异常提报 按钮弹框 -->
<template>
    <el-dialog :title="title" :visible.sync="open" width="350px" append-to-body>
        <el-form ref="formRef" :model="form" :rules="rules">
            <el-form-item label="异常分类" prop="typeId" style="flex: 0 0 50%" class="sort">
                <el-cascader v-model="form.typeIds" :options="sortType" collapse-tags :props="{
                    expandTrigger: 'hover',
                    value: 'id',
                    multiple: true,
                    label: 'excepDesc',
                    children: 'childList',
                }" style="width: 100%">
                </el-cascader>
            </el-form-item>
            <el-form-item label="SQE判定人" prop="auditPerson" style="flex: 0 0 50%" class="sort">
                <el-select v-model="form.auditPerson" filterable placeholder="请选择SQE判定人" style="width: 100%;">
                    <el-option v-for="(item, index) in adminList" :key="index" :label="item.userName"
                        :value="item.userName">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import moment from "moment";
import { getinspectData, submitExceptionRecord } from "@/api/mes/qc/iqc";
import {
    getTreeList
} from "@/api/system/record";
import {
    getAdminList
} from "@/api/system/follow";
export default {
    name: "reviewDetails",
    data() {
        return {
            title: "异常提报",
            open: false,
            rowInfo: {},
            form: {
                typeId: null,
                typeIds: [],
            },
            rules: {
                // typeId: [
                //   { required: true, message: "请选择异常分类", trigger: "blur" },
                // ],
                typeIds: [
                    { required: true, message: "请选择异常分类", trigger: "blur" },
                ],
                auditPerson: [{ required: true, message: '请选择SQE判定人', trigger: 'change' }],
            },
            sortType: [],
            adminList: [],
            iqcInspectData: {}
        };
    },
    methods: {
        //初始化函数
        init(row) {
            this.rowInfo = row
            this.open = true;
            this.getSortTypeTreeList();
            this.getAdminList();
        },
        // 获取异常分类数据
        getSortTypeTreeList() {
            getTreeList().then((res) => {
                let data = res.data ? res.data : [];
                data.forEach((item) => {
                    item.childList.forEach((item2) => {
                        delete item2.childList;
                    });
                });
                this.sortType = data;
            });
        },
        // 获取SQE判定人数据
        getAdminList() {
            let param = {
                pageNum: 1,
                pageSize: 10000,
            };
            getAdminList(param).then((res) => {
                this.adminList = res.rows ? res.rows : [];
            });
        },
        // 提交按钮
        submitForm() {
            this.$refs.formRef.validate((valid) => {
                if (valid) {
                    // ProExceptionRecord
                    let param = {
                        typeIds: this.form.typeIds,
                        typeIdStr: '',
                        typeId: this.form.typeId,
                        excepDesc: '', //异常分类
                        source: this.rowInfo.headId, //取iqcInspect接口中headid的值
                        auditPerson: this.form.auditPerson, //SQE判定人
                    }
                    let _form = JSON.parse(JSON.stringify(this.form));
                    param.typeIds = _form.typeIds.map((item) => { return item[1] });
                    console.info(_form, param)
                    submitExceptionRecord(param).then((res) => {
                        this.$modal.msgSuccess("提交成功");
                        this.$refs.formRef.resetFields(); // 清空表单数据
                        this.open = false;
                    }).catch(() => { })
                } else {
                    return false;
                }
            });
        },
        /* 取消按钮 */
        cancel() {
            this.open = false;
            this.form = {}
            this.$refs.formRef && this.$refs.formRef.resetFields(); // 清空表单数据
        },
    }
}
</script>
<style lang='scss' scoped>
.dialog-footer {
    padding-top: 20px;
    text-align: center;
}

.sn-title {
    background-color: #ddd;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.sn-title :deep(.el-checkbox .el-checkbox__label) {
    color: #fff !important;
}
</style>